package com.example.rabbitmq.factory;

import com.example.rabbitmq.entity.RabbitmqInfoPo;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author songyahui
 * @Date 2023/7/7 9:25
 * @Description
 */
public class RabbitmqConFactory {

    public static Channel getChannel(RabbitmqInfoPo po) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        //工厂IP 连接rabbitmq队列
        factory.setHost(po.getHost());
        //设置用户名称
        factory.setUsername(po.getUserName());
        //设置密码
        factory.setUsername(po.getPassWd());
        //创建连接
        Connection connection = factory.newConnection();
        //获取信道
        return connection.createChannel();
    }
}
